package com.util;

import java.text.MessageFormat;

import org.apache.log4j.MDC;

/**
 * @author KENNETHLCH
 * @version $Id: LogUtil.java,v 1.1.1.1 2013/08/16 05:35:48 tengyang Exp $
 */
public class LogUtil {

    public static void setThreadID() {
        MDC.put("threadID",
                MessageFormat.format("{0}:{1}", 
                        Thread.currentThread().getName(),
                        Integer.toHexString(Thread.currentThread().hashCode())
                ));
    }
    
    public static void setSessionID(String sid) {
        MDC.put("sessionID", sid);
    }
    
    public static void setUserID(String uid) {
        MDC.put("userID", uid);
    }
    
    /**
     * Clears all diagnostic contexts.
     */
    public static void clearDC() {
        MDC.remove("threadID");
        MDC.remove("sessionID");
        MDC.remove("userID");
    }
}
